﻿@model List<PollAnswer>
<ul id="_pollAnswerPanel">
    @if (Model != null)
    {

        foreach (PollAnswer a in Model)
        {
        <li>
            @Html.TextBox("answer", a.Answer, new { @class = "input" })
            @Html.Link("javascript://", " ", new { @class = "ui-button icon-16 del", onclick = "" })
        </li>
        }
    }
    else
    {
        for (int i = 0; i < 8; i++)
        {
        <li>
            @Html.TextBox("answer", "", new { @class = "input" })
            @Html.Link("javascript://", " ", new { @class = "ui-button icon-16 del", onclick = "" })
        </li>
        }
    }
</ul>

<div class="white-t">

@Html.Link("javascript://", ForumContext.GetText(LanguageSection.POST, "ADD_ANSWER"), new { onclick = "addAnswer(1)",@class="ui-button icon-16 add" })
</div>



@using(Html.BeginScriptBlock())
{
    <script type="text/javascript">
        var _totalAnswer = 10;

        function addAnswer(val) {

            var _parent = $('#_pollAnswerPanel');

            var _stt = _parent.children().length;

            if (_stt >= _totalAnswer) {

                $('#_addAnswer').hide();
            }

            for (var i = 0; i < val; i++) {

                _stt = _stt + 1;

                if (_stt > _totalAnswer) return;

                var _html = '<li id="_answer' + _stt + '"><input type="text" name="answer" class="input" /><a class="ui-button icon-16 del" onclick="delAnswer(\'#_answer' + _stt + '\')"></a></li>';
                _parent.append(_html);

            }

        }

        function delAnswer(id) {

            $(id).fadeOut(500, function () {
                $(this).remove();
                $('#_addAnswer').show();
            });

        }
    </script>
}